package com.weipai.springboot.module.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.News;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ${lyh} on 2018/8/28.
 *
 * 消息中心 模块
 */
@RestController
@RequestMapping("/news/")
public class NewsController {

    @Autowired
    NewsService newsService;



    /*
         按消息类型 获取不同消息列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public Response list( Integer page,
                                     Integer size,
                                     String userId,
                                     String types){
        Response response = new Response();
        PageHelper.startPage(page, size);
        List<News> list = newsService.selectAllByNewsTypes(userId,types);

        PageInfo<News> pageInfo = new PageInfo<>(list);
        if(list.size()>0){
            response.setCode(RetCode.SUCCESS);
            response.put("pageData", pageInfo.getList());
            response.put("recordsTotal", pageInfo.getTotal());
            response.put("pages", pageInfo.getPages());
        }else{
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }


    /*
        物流详情接口
     */
    @GetMapping("/getLogisticsById/{id}")
    public Response getLogisticsById(@PathVariable("id")  String id){
        return newsService.getLogisticsById(id);
    }

}
